#include <stdio.h>

void print_array(float matrix[4][5]);

main()
{
  int i,k,j,maximum,a,b;
  float matrix[4][5],v;
  double X1,X2,X3,X4;
   
    FILE *inf,*outf;
    outf= stdout;
    
    fprintf(outf, "gauss\n");                                  
    fprintf(outf, "2102\n");
    fprintf(outf, "Mikhailov Vlad\n");
    fprintf(outf, "\n");
    fprintf(outf, "Enter a:");
    scanf("%d",&a);
    getchar();
    fprintf(outf, "Enter b:");
    scanf("%d",&b);
    getchar();
       
    matrix[0][0]=a-6;
    matrix[0][1]=1;
    matrix[0][2]=1;
    matrix[0][3]=1;
    matrix[0][4]=b-4;
    
    matrix[1][0]=1;
    matrix[1][1]=a-4;
    matrix[1][2]=1;
    matrix[1][3]=1;
    matrix[1][4]=b-2;

    matrix[2][0]=1;
    matrix[2][1]=1;
    matrix[2][2]=a-2;
    matrix[2][3]=1;
    matrix[2][4]=b;
    
    matrix[3][0]=1;
    matrix[3][1]=1;
    matrix[3][2]=1;
    matrix[3][3]=a;
    matrix[3][4]=b+2;    
                            
  print_array(matrix);
  printf("\n");
  
  for(i=0;i<4;++i)
  {
   maximum=i;
   for(j=i+1;j<4;++j)
     if (matrix[j][i]>matrix[maximum][i])
       maximum=j;
   for(j=0;j<5;++j){
     v=matrix[maximum][j];
     matrix[maximum][j]=matrix[i][j];
     matrix[i][j]=v;
   }
   for(j=4;j>=i;--j)
     for(k=i+1;k<4;++k)
       matrix[k][j]-=matrix[k][i]/matrix[i][i]*matrix[i][j];
}                                    
 for(i=4-1;i>=0;--i)
{
   matrix[i][4]=matrix[i][4]/matrix[i][i];
   matrix[i][i]=1;
   for(j=i-1;j>=0;--j)
   {
     matrix[j][4]-=matrix[j][i]*matrix[i][4];
     matrix[j][i]=0;
   }
}                                                     
 print_array(matrix);

  X1=(a-6)*matrix[0][4]+matrix[1][4]+matrix[2][4]+matrix[3][4];
  X2=matrix[0][4]+(a-4)*matrix[1][4]+matrix[2][4]+matrix[3][4];
  X3=matrix[0][4]+matrix[1][4]+(a-2)*matrix[2][4]+matrix[3][4];
  X4=matrix[0][4]+matrix[1][4]+matrix[2][4]+a*matrix[3][4];
  
  fprintf(outf, "Accuracy:\n");
  printf("%2.9f\n", X1);
  printf("%2.9f\n", X2);
  printf("%2.9f\n", X3);
  printf("%2.9f\n", X4);
  
  getchar();
  return 0;                               
}

void print_array(float matrix[4][5])
{
  int i,j;
  for(i=0;i<=3;i++,printf("\n"))
  {
                   for(j=0;j<=4;j++)
                   printf( "%2.9f""  ", matrix[i][j]);
  }
  return;    
}

